package com.holly.unit.bpmn.activiti.ext;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.holly.unit.auth.api.pojo.login.LoginUser;
import com.holly.unit.bpmn.activiti.entity.ActivitiZNode;
import com.holly.unit.bpmn.activiti.mapper.ActivitiZNodeMapper;
import com.holly.unit.bpmn.activiti.pojo.ActivitiDepartment;
import com.holly.unit.bpmn.activiti.pojo.ActivitiRole;
import com.holly.unit.bpmn.api.pojo.BpmnUser;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类描述: 流程节点扩展类
 *
 * @author fxr
 * @version 1.0.0
 * @date 2022/2/21 15:30
 */
@Service
public class ActivitiZNodeService extends ServiceImpl<ActivitiZNodeMapper, ActivitiZNode> {



    public List<LoginUser> queryAllUser() {
        return this.baseMapper.queryAllUser();
    }

    /***
     * 根据账户获取角色信息
     * @param account 账户
     * @return
     */
    public List<String> queryRoleByAccount(String account) {
        return this.baseMapper.selectRoleByUserName(account);
    }


    /***
     * 根据id删除node
     * @param id node_id这个字段
     * @return
     */
    public boolean deleteByNodeId(String id) {
        return this.remove(new LambdaQueryWrapper<ActivitiZNode>().eq(ActivitiZNode::getNodeId,id));
    }

    /***
     * 批量删除node
     * @param ids node_id 这个字段
     * @return
     */
    public boolean deleteBathNodeUsers(List<String> ids) {
        return this.removeByIds(ids);
    }

    public List<ActivitiZNode> findByNodeIdAndType(String nodeId, int type) {
        return list(new LambdaQueryWrapper<ActivitiZNode>().eq(ActivitiZNode::getNodeId,nodeId).eq(ActivitiZNode::getType,type));
    }

    public Boolean hasChooseDepHeader(String nodeId) {
        List<ActivitiZNode> listNode = findByNodeIdAndType(nodeId, 4);
        if(listNode!=null&&listNode.size()>0){
            return true;
        }
        return false;
    }
    public Boolean hasChooseSponsor(String nodeId) {
        List<ActivitiZNode> listNode = findByNodeIdAndType(nodeId, 3);
        if(listNode!=null&&listNode.size()>0){
            return true;
        }
        return false;
    }

    // 根据节点的id查询用户信息
    public List<LoginUser> findUserByNodeId(String nodeId){
        return this.baseMapper.selectUserByNodeId(nodeId);
    }
    // 根据节点的id查询角色
    public List<ActivitiRole> findRoleByNodeId(String nodeId) {
        return this.baseMapper.selectRoleByNodeId(nodeId);
    }
    // 根据节点的id查询机构
    public List<ActivitiDepartment> findDepartmentByNodeId(String nodeId) {
        return this.baseMapper.selectDepartmentByNodeId(nodeId);
    }

    // 根据角色id查询用户信息

    public List<LoginUser> findUserByRoleId(String id) {
        return this.baseMapper.selectUserByRoleId(id);
    }

    // 根据机构id查询用户信息
    public List<LoginUser> findUserDepartmentId(String id) {
        return this.baseMapper.selectUserDepartmentId(id);
    }

    // 根据账户的信息获取机构ids
    public List<String> getOrgIdsByAccount(String account) {
        return this.baseMapper.getDepartIdsByUsername(account);
    }

    // 根据账户信息获取用户信息
    public BpmnUser getUserByAccount(String account){
        return this.baseMapper.getUserByAccount(account);
    }
}
